package com.vehicle.manage.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.vehicle.manage.domain.VehicleFence;
import com.vehicle.manage.service.IVehicleFenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 围栏管理Controller
 * 
 * @author ruoyi
 * @date 2023-05-29
 */
@RestController
@RequestMapping("/fence")
public class VehicleFenceController extends BaseController
{
    @Autowired
    private IVehicleFenceService vehicleFenceService;

    /**
     * 查询围栏管理列表
     */
    @RequiresPermissions("fence:manage:list")
    @GetMapping("/list")
    public TableDataInfo list(VehicleFence vehicleFence){
        startPage();
        List<VehicleFence> list = vehicleFenceService.selectVehicleFenceList(vehicleFence);
        return getDataTable(list);
    }

    /**
     * 导出围栏管理列表
     */
    @RequiresPermissions("fence:manage:export")
    @Log(title = "围栏管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VehicleFence vehicleFence){
        List<VehicleFence> list = vehicleFenceService.selectVehicleFenceList(vehicleFence);
        ExcelUtil<VehicleFence> util = new ExcelUtil<VehicleFence>(VehicleFence.class);
        util.exportExcel(response, list, "围栏管理数据");
    }

    /**
     * 获取围栏管理详细信息
     */
    @RequiresPermissions("fence:manage:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id){
        return success(vehicleFenceService.selectVehicleFenceById(id));
    }

    /**
     * 新增围栏管理
     */
    @RequiresPermissions("fence:manage:add")
    @Log(title = "围栏管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VehicleFence vehicleFence){
        return toAjax(vehicleFenceService.insertVehicleFence(vehicleFence));
    }

    /**
     * 修改围栏管理
     */
    @RequiresPermissions("fence:manage:edit")
    @Log(title = "围栏管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VehicleFence vehicleFence){
        return toAjax(vehicleFenceService.updateVehicleFence(vehicleFence));
    }

    /**
     * 删除围栏管理
     */
    @RequiresPermissions("fence:manage:remove")
    @Log(title = "围栏管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids){
        return toAjax(vehicleFenceService.deleteVehicleFenceByIds(ids));
    }

    @PostMapping("/saveFenceData")
    public AjaxResult saveFenceData(@RequestBody VehicleFence vehicleFence){
        return toAjax(vehicleFenceService.saveFenceData(vehicleFence));
    }
}
